/*
 * @Author: your name
 * @Date: 2021-03-05 19:39:53
 * @LastEditTime: 2021-03-09 19:21:49
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \day\src\pages\main\class\studentManger.tsx
 */
import React, { useEffect } from 'react';
import studentMangeCss from "./studentmange.less"
import { FC } from "react";
import { Table,Space,Input} from 'antd';
import { useDispatch, useSelector, StudentModelState, useLocation, useHistory } from 'umi';
const { Column} = Table;
const StudentManger: FC = () => {
  const dispatch = useDispatch();
  useEffect(() => {
    dispatch({
      type: 'students/getStudents',
    })
  }, [])
  let {Students}=useSelector((model:{students:StudentModelState}) => model.students)
  //删除
   const Del = (values: any) => {
     console.log(values.student_id)
     dispatch({
      type: 'students/DelStudent',
      payload: {
        id:values.student_id
      }
    })
   }
   //获取input值
   let data=""
   const value=(e:any)=>{
     console.log(e)
     data=e.nativeEvent.data
   }
   //点击查询
   const inquire=()=>{
     console.log(data)
     let cxData = Students.filter( v => {
      return JSON.stringify(v.student_name).indexOf(data) !== -1
    });
    console.log(cxData);
   }

   //重置
   const reset=()=>{
    data=""
    console.log(data)
   }
  return (
    <div className={studentMangeCss.Student}>
      <div className={studentMangeCss.search}>
        <div className={studentMangeCss.ser}>
          <Input placeholder="输入学生姓名" onChange={(e: any) => value(e)}/>
          <button onClick={()=>inquire()}>查询</button>
          <button onClick={()=>reset()}>重置</button>
        </div>
      </div>
      <div className={studentMangeCss.stu} >
        <Table dataSource={Students}>
          <Column title="姓名" dataIndex="student_id" key="index"/>
          <Column title="学号" dataIndex="student_name" key="index" />
          <Column title="班级" dataIndex="grade_name" key="index" />
          <Column title="教室" dataIndex="room_text"  key="index"/>
          <Column title="密码" dataIndex="student_pwd"  key="index"/>
          <Column
            title="操作"
            key="index"
            render={(text: any) => (
              <Space size="middle" >
                <a onClick={() => Del(text)}>删除</a>
              </Space>
            )}
          />
        </Table>,
        </div>
    </div>
  );
}
export default StudentManger
